<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>09 多维数组的遍历</title>
    <style>
        h1 {
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>09 多维数组的遍历</h1>
</body>
<script>
    /* 
        多维数组
    */

    // 1、数组里面有数组
    var arr = [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]
    ];

    // console.log(arr.length);
    // console.log(arr);

    for (var i = 0; i < arr.length; i++) {
        for (var j = 0; j < arr[i].length; j++) {
            console.log(arr[i][j]);
        }
    }

    // 2、对象里面有对象
    var obj = {
        gid: 1001,
        title: '小米',
        opt: {
            opt1: '黑色',
            opt2: '红色',
            opt3: '黄色'
        }
    }

    // 遍历
    for (var key in obj) {
        // console.log(obj[key]);
        for (var i in obj[key]) {
            console.log(obj[key][i]);
        }
    }

    // 3、数组和对象的结合
    var goodslist = [
        {
            'gid': 101,
            'title': '华为',
            'price': 7999
        },
        {
            'gid': 102,
            'title': '小米',
            'price': 4999
        },
        {
            'gid': 103,
            'title': '苹果',
            'price': 9999
        },
    ];

    // console.log(goodslist[0].title);
    // console.log(goodslist[0]['title']);

    for (var i = 0; i < goodslist.length; i++) {
        for (var key in goodslist[i]) {
            console.log(goodslist[i][key]);
        }
    }

</script>

</html>